package com.ysd.dao.Impl;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import com.ysd.entity.Product;
import com.ysd.util.DBManager;

public class ZhuYeTuDaoImpl {
	//显示主页产品图
	public ArrayList<Product> getZhuYeList(){
		ArrayList<Product> zhuye=new ArrayList<Product>();
		Connection conn=DBManager.getConnection();//建立连接
		Statement st=null;
		ResultSet rs=null;
		try {
			st=conn.createStatement();//创建statement对象
			rs=st.executeQuery("select * from product order by rand() limit 6");//使用sql语句（随机显示六个）
			while(rs.next()) {//遍历结果集
				int productId=rs.getInt("productId");
   			    String productName=rs.getString("productName");
   			    String productImg=rs.getString("productImg");
   			    Product product=new Product(productId,productName,productImg); 
   			    zhuye.add(product);
			}
			return zhuye;
		} catch (SQLException e) {
			e.printStackTrace();
			return null;
		}finally {
			DBManager.closeAll(conn, st, rs);
		}
	}
}
